package com.epower.web.action.app.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.epower.base.BaseAction;
import com.epower.bo.epower.commons.Result;
import com.epower.bo.epoweruserword.EpowerUserWordService;
import com.epower.dataobject.EpowerUserWordDO;

/**
 * @author bolin.hbc
 * 
 *         用户单词的action
 */
@Scope("prototype")
@Component("wuserword")
public class UserWordAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Integer userid;
	private Integer bookid;
	private Integer level;
	private EpowerUserWordService epowerUserWordBO;
	Result result = Result.succResult();

	public String doGetUserWords() {

		if (userid == null) {
			result = Result.errorResult(Result.RESULTCODE_PARAMETER_ILLEGAL, "userid can't be null");
			return ERROR;
		}

		EpowerUserWordDO userWord = new EpowerUserWordDO();
		userWord.setBookid(bookid);
		userWord.setLevel(level);
		userWord.setUserid(userid);
		List<EpowerUserWordDO> userWordList = epowerUserWordBO.getEpowerUserWordListByOption(userWord);
		List<TmpUserWord> tmps = new ArrayList<TmpUserWord>();
		for (EpowerUserWordDO uw : userWordList) {
			TmpUserWord tmp = new TmpUserWord();
			tmp.setBookid(uw.getBookid());
			tmp.setLevel(uw.getLevel());
			tmp.setUserid(uw.getUserid());
			tmp.setWordid(uw.getWordid());
			tmps.add(tmp);
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("userwords", tmps);
		result.setResult(resultMap);
		return SUCCESS;
	}

	public Integer getUserid() {
		return userid;
	}

	public void setUserid(Integer userid) {
		this.userid = userid;
	}

	public Integer getBookid() {
		return bookid;
	}

	public void setBookid(Integer bookid) {
		this.bookid = bookid;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Result getResult() {
		return result;
	}

	public void setResult(Result result) {
		this.result = result;
	}

	public void setEpowerUserWordBO(EpowerUserWordService epowerUserWordBO) {
		this.epowerUserWordBO = epowerUserWordBO;
	}

	public class TmpUserWord {
		private Integer userid;
		private Integer bookid;
		private Integer wordid;
		private Integer level;

		public Integer getUserid() {
			return userid;
		}

		public void setUserid(Integer userid) {
			this.userid = userid;
		}

		public Integer getBookid() {
			return bookid;
		}

		public void setBookid(Integer bookid) {
			this.bookid = bookid;
		}

		public Integer getWordid() {
			return wordid;
		}

		public void setWordid(Integer wordid) {
			this.wordid = wordid;
		}

		public Integer getLevel() {
			return level;
		}

		public void setLevel(Integer level) {
			this.level = level;
		}

	}
}
